<?php
require_once 'Response.php';
require_once 'DB.php';
header('Content-Type:text/json;charset=utf-8');
# 设置允许跨域
header("Access-Control-Allow-Origin: *");

//$pdo = DB::getInstance()->connect();
//function json($code=0,$message='',$data= []) {
//    $ret = [
//        'code'=>$code,
//        'message'=>$message,
//        'data'=>$data
//    ];
//    exit (json_encode ($ret,JSON_UNESCAPED_UNICODE));
//
//}

$name=$_FILES['file']['name'];
$tmp=strrchr($name,'.');
$newname=date('YmdHis').rand(100,999).$tmp;
if (is_uploaded_file($_FILES['file']['tmp_name'])){
    if (move_uploaded_file($_FILES['file']['tmp_name'],'./uploads/'.$newname)){
        echo 'http://localhost:8081/exec/milktea/uploads/'.$newname;
    }else{
        echo 0;
    }
}
//if (!empty($name)){
//    //2.上传新的
////    $file='C:\Users\liuyahui\Desktop\imgs'.$name;
////    $newFile='./uploads'.$name;
////    copy($file,$newFile);
//    //$file=$_FILES['pic'];
//    //move_uploaded_file($name,'./uploads/'.$name);
//    //$icon=$file['name'];
//    json(1,'上传成功',['path'=>$name]);
//}else{
//    json(-1,'图片不存在！');
//}




//3、查询
//$sql='SELECT * FROM `menu`';
////$sql='SELECT news.*,name FROM `news` LEFT JOIN news_type ON news.type_id=news_type.id '.$str_search.'ORDER BY id DESC LIMIT '.($curr-1)*$per.','.$per;
////$stmt = $pdo->query($sql); //返回一个PDOStatement对象
////$data = $stmt->fetchAll();//获得所有
//$stmt=$pdo->query($sql);
//$menulist=$stmt->fetchall();
//Response::json('200','查询成功',$menulist);


?>


